package weak_20241227_29.stream;

import java.util.ArrayList;
import java.util.function.Predicate;

/**
 * @author zdl
 * @date 2024/12/27
 */
public class Demo11 {
    public static void main(String[] args) {
        //11. 检查整数列表中是否包含连续的数字
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(4);
        list.add(9);
        list.add(1);
        boolean b1 = list.stream().anyMatch(new Predicate<Integer>() {
            @Override
            public boolean test(Integer i1) {
                return list.stream().anyMatch(new Predicate<Integer>() {
                    @Override
                    public boolean test(Integer i2) {
                        return Math.abs(i1 - i2) == 1;
                    }
                });
            }
        });

        boolean b = list.stream().anyMatch(n -> list.stream().anyMatch(m -> Math.abs(n - m) == 1));
        System.out.println(b);
    }
}
